/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: WHY
 * Date: 2023-03-26
 * Time: 13:53
 */
//饿汉模式
class Singleton{
    //创建唯一一个实例
    private static Singleton  instance=new Singleton();
    //获取唯一实例
    public static Singleton getInstance(){
        return instance;
    }
        //构造方法私有化,保证不能再new实例
    private Singleton(){

    }
}

public class ThreadingDemo1 {

    public static void main(String[] args) {
            Singleton s1=Singleton.getInstance();
            Singleton s2=Singleton.getInstance();
            //Singleton s3=new Singleton();
    }
}
